package logic

import (
	"context"
	"goods_srv/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHouseLogic {
	return &ListHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListHouseLogic) ListHouse(req *types.ListHouseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	house, err := l.svcCtx.Goods.ListHouse(l.ctx, &goods.ListHouseRequest{
		UserId:    req.UserId,
		Status:    req.Status,
		StartRent: float32(req.StartRent),
		EndRent:   float32(req.EndRent),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "房源列表展示成功",
		Data: house,
	}, nil
}
